/*
 * FileChooser.java
 *
 * Created on 5 Сентябрь 2008 г., 12:45
 */

package jmath;

import java.io.*;
import javax.swing.*;
/**
 *
 * @author  timon
 */
public class FileChooser extends javax.swing.JFrame {
    
    /** Creates new form FileChooser */
    public FileChooser() {
        initComponents();        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jFileChooser1.setName("jFileChooser1"); // NOI18N
        jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFileChooser1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jFileChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jFileChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {
    	
    	//GEN-FIRST:event_jFileChooser1ActionPerformed
        // TODO add your handling code here:
    	
    	//System.out.println(jFileChooser1.getSelectedFile());
    	
    	
    }//GEN-LAST:event_jFileChooser1ActionPerformed
    
    
    public File getFileForSave(){
    	if(JFileChooser.APPROVE_OPTION==jFileChooser1.showSaveDialog(null)){
    		return jFileChooser1.getSelectedFile();
    	}
    	jFileChooser1.setVisible(false);
    	return null;
    }
    
    public File openFile() {
    	if(JFileChooser.APPROVE_OPTION==jFileChooser1.showOpenDialog(null)){
    		return jFileChooser1.getSelectedFile();
    	}
    	jFileChooser1.setVisible(false);
    	return null;
	}
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FileChooser().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JFileChooser jFileChooser1;
    // End of variables declaration//GEN-END:variables
    
}
